package 网络编程;

import java.io.*;
import java.net.Inet6Address;
import java.net.Socket;

/**
 *
 */
public class SocketTest {

    public static void main(String[] args) throws IOException {

        Socket socket = new Socket(Inet6Address.getLocalHost().getHostAddress(), 6666);

        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bufferedWriter.write("my is client");
        // 注意: 这里需要换行，刷新
        bufferedWriter.newLine();
        bufferedWriter.flush();

        // 将流中数据输入到程序中
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        System.out.println("client receipt: " + bufferedReader.readLine());

        //关闭输入流，关闭Socket;
        bufferedWriter.close();
        bufferedReader.close();
        socket.close();
    }

}
